﻿<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

$title = "Maintenances - Travaux";
$tplinc = "maintenances-details";
$parse = 1;

	if (isset($_GET['id']) && !empty($_GET['id']))
	{
		echo $id_maint = intval($_GET['id']);
		
		$sql = query("SELECT * FROM maintenance WHERE id = '".$id_maint."'");
		
		if (mysql_num_rows($sql) == 1)
		{		
			$resultat_maint = mysql_fetch_array($sql);
			
			$type_array = array(
							'1' => 'Maintenance',
							'2' => 'Mise à jour',
							'3' => 'Incident',
							'4' => 'Installation',
							);
							
			$severite_array = array('1' => 'Basse',
									'2' => 'Moyenne',
									'3' => 'Haute',
									'4' => 'Critique',
									);
									
			$etat_array = array('0' => 'Annuler',
								'1' => 'En cours',
								'2' => 'En pause',
								'3' => 'Terminé',
								);
								
			$cat_array = array( '1' => 'Noms de domaine',
								'2' => 'Hébergement multualisé',
								'3' => 'Panel',
								'4' => 'Datacenter',
								);
								
			$binaire_array = array(	'0' => 'Non',
									'1' => 'Oui',
									);
								
			$titre = $result_maint['titre'];
			$id = $result_maint['id'];
			$type = $result_maint['type'];
			$etat = $result_maint['etat'];
			$severite = $result_maint['level_severite'];
			$poucentage = $result_maint['pourcent_fini'];
			$cat = $result_maint['categorie'];
			$details = $result_maint['details'];
			$date_ouvert = $result_maint['date_ouvert'];
			$fermer = $result_maint['fermer'];
			
			$next_maint = query("SELECT * FROM maintenance WHERE id > '".$id."' ORDER BY id  LIMIT 0, 1");
			
			if (mysql_num_rows($next_maint) == 1)
			{
				$tpl->assign(array('next' => 1));
				$next_maint_result = mysql_fetch_array($next_maint);
				$id_next = $next_maint_result['id'];
				$titre_next = $next_maint_result['titre'];
				$pourcentage_next = $next_maint_result['pourcent_fini'];
				$etat_next = $next_maint_result['etat'];
			}
			else
				$tpl->assign(array('next' => 0));
				
			$last_maint = query("SELECT * FROM maintenance WHERE id < '".$id."' ORDER BY id LIMIT 0, 1");
				
			if (mysql_num_rows($last_maint) == 1)
			{
				$tpl->assign(array('last' => 1));
				$last_maint_result = mysql_fetch_array($last_maint);
				$id_last = $last_maint_result['id'];
				$titre_last = $last_maint_result['titre'];
				$pourcentage_last = $last_maint_result['pourcent_fini'];
				$etat_last = $last_maint_result['etat'];
			}
			else
				$tpl->assign(array('last' => 0));
			
			

								
			$tpl->assign(array(
								'type' => $type_array[$type],
								'titre' => $titre,
								'titre_next' => $titre_next,
								'titre_last' => $titre_last,
								'id' => $id,
								'id_next' => $id_next,
								'id_last' => $id_last,
								'details' => $details,
								'severite' => $severite_array[$severite],
								'date_ouvert' => $date_ouvert,
								'etat' => $etat_array[$etat],
								'etat_next' => $etat_array[$etat_next],
								'etat_last' => $etat_array[$etat_last],
								'fermer' => $binaire_array[$fermer],
								'pourcentage' => $pourcentage,
								'pourcent_next' => $pourcentage_next,
								'pourcent_last' => $pourcentage_last,
							));
								
		}
		else
		{
			header("Location: index.html");
		}
	}
	else
	{
		header("Location: index.html");
	}